package chapter2;

public class 数据查询 {
    public static void main(String[] args) {
        int[] nums = {1,2,3,4,5,6,7,8};
        int targetNum = 3;
        int start = 0;
        int end = nums.length - 1;
        int mid = 0;
        while ( start <= end ) {
            mid = (end + start) / 2;
            if (nums[mid] > targetNum) {
                end = mid - 1;
            }else if (nums[mid] < targetNum) {
                start = mid + 1;
            }else {
                break;
            }

        }
        System.out.println("数据的位置在" + targetNum);
    }

}
